<?php
class Public_Comment_ModerationSuccessView extends BlogPublicBaseView
{
    public function executeHtml(AgaviRequestDataHolder $rd)
    {
        $this->setupHtml($rd, 'blog');
        $ro = $this->getContext()->getRouting();
        /* @var $comments_model Public_CommentsModel */
        $comments_model = $this->getContext()->getModel('Comments', 'Public');
        /* @var $posts_model Public_PostsModel */
        $posts_model = $this->getContext()->getModel('Posts', 'Public');
        $comments = array();
        foreach ($comments_model->findNotApprovedComments() as $c) {
            /* @var $c Comment */
            
            $user = $c->User;
            $post = $c->Post;
            $pc = $posts_model->getPostCoordinates($post);
            $post_url = $ro->gen('post.view', $pc, array('relative'=>false));
            $comment_url = sprintf('%s#c%d', $post_url, $c->id);
            
            $display_name = $c->display_name;
            if (is_null($display_name)) {
                if ($user instanceof User) {
                    $display_name = $user->display_name;
                } elseif ($c->is_owner_comment) {
                    $display_name = WereWordConfig::get('blog.owner_name');
                } else {
                    $display_name = '%username%';
                }
            }
            $comments[] = array(
                'id' => $c->id,
                'time' => $c->comment_time,
                'text' => $c->comment_text,
                'website' => $c->website,
                'name' => $display_name,
                'email' => $c->email,
                'is_user' => $user instanceof User,
                'is_owner' => $c->is_owner_comment,
                'approved' => $c->is_approved,
                'type' => $user instanceof User ? $user->user_type : 'guest',
                'comment_url' => $comment_url,
                );
              
        }
        $this->setAttribute('comments', $comments);
        $this->setAttribute('submit_route', $ro->gen('comment.moderation'));
        $this->setAttribute('title', 'Comments moderation');
    }
}
?>
